package com.luckynote.common.base.dubbo;

import com.luckynote.common.base.config.AppConfig;
import org.apache.dubbo.rpc.*;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <pre>
 * *********************************************
 * Copyright LUCKY-NOTE.
 * All rights reserved.
 * ****************************************************
 *  Version       Date         Author            Desc
 *    v1.0       2019/7/7      bingo            日志隐式传参获取值
 * ****************************************************
 * </pre>
 */
public class LogConfirmFilter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        MDC.put(LogEnum.TRACE_ID.getCode(), invocation.getAttachment(LogEnum.TRACE_ID.getCode()));
        String moduleName = invocation.getAttachment(LogEnum.MODULE_NAME.getCode());
        MDC.put(LogEnum.MODULE_NAME.getCode(), AppConfig.getProjectName() +","+ moduleName);
        Result invoke = invoker.invoke(invocation);
        MDC.clear();
        return invoke;
    }
}
